#ifndef __SO_BASE__
#define __SO_BASE__
#include "define.h"
class CSOBase
{
public:
	CString m_workDir;
	std::vector<docResult> m_result;
	virtual std::vector<CString> getConfig()=0;
	//nR,nF,nF,pR,pP,pF,F
	void getRandM(std::vector<double>& rates,_2DMatrix& matrix)
	{
		int nn(0),np(0),pn(0),pp(0);
		for(int i=0;i<(int)m_result.size();i++)
		{
			if(m_result[i].clsId==SNEG&&
			   m_result[i].setId==SNEG)
			{
				nn++;
			}
			else if(m_result[i].clsId==SNEG&&
			   m_result[i].setId==SPOS)
			{
				np++;
			}
			else if(m_result[i].clsId==SPOS&&
			   m_result[i].setId==SNEG)
			{
				pn++;
			 }
			 else if(m_result[i].clsId==SPOS&&
			   m_result[i].setId==SPOS)
			{
				pp++;
			}
		}
		
		rates.push_back((double)(1.0*nn)/(nn+np));
		rates.push_back((double)(1.0*nn)/(nn+pn));
		rates.push_back((double)(1.0*pp)/(pn+pp));
		rates.push_back((double)(1.0*pp)/(pp+np));
		rates.push_back((double)(1.0*(nn+pp))/(nn+pp+pn+np));
		std::vector<int> vec1,vec2;
		vec1.push_back(nn);
		vec1.push_back(np);
		vec2.push_back(pn);
		vec2.push_back(pp);
		matrix.push_back(vec1);
		matrix.push_back(vec2);
	}
	void initResult(CString filename)
	{
		FILE_READ(iFile,filename)
		{
			CString tmp,filename;	
			docResult dR;
			iFile.ReadString(tmp);
			sscanf(tmp,"%s %d",filename,&dR.clsId);
			dR.filename.Format("%s",filename);
			m_result.push_back(dR);
		}
		
		iFile.Close();
	}
protected:
	int ranResult(int negCount,int posCount)
	{
		if(negCount==0&&posCount==0)
		{
			negCount=1;
			posCount=1; 
		}
		int range=100;
		int line=range*negCount/(negCount+posCount);
		int ran=rand()%range;
		do
		{
			if(ran<line)
				return SNEG;
			else if(ran>line)
				return SPOS;
			ran=rand()%range;
		}
		while(ran==line);
	}
};
#endif